package com.blackcat.v2.demo;

public class Light implements MyLifecycle {

    private MyLifecycleSupport lifecycle = new MyLifecycleSupport(this);

    private String name ;

    public Light(String name) {
        this.name = name;
    }

    @Override
    public void start() {
        lifecycle.fireLifecycleEvent(MyLifecycle.BEFORE_START, null);
        System.out.println("大灯"+ this.name +"开始发光...");
        lifecycle.fireLifecycleEvent(MyLifecycle.AFTER_START, null);
    }

    @Override
    public void stop() {
        lifecycle.fireLifecycleEvent(MyLifecycle.BEFORE_STOP, null);
        System.out.println("大灯"+ this.name +"关闭...");
        lifecycle.fireLifecycleEvent(MyLifecycle.AFTER_STOP, null);
    }

    @Override
    public void addLifecycleListener(MyLifecycleListener listener) {
        lifecycle.addLifecycleListener(listener);
    }

    @Override
    public MyLifecycleListener[] getLifecycleEvents() {
        return lifecycle.getLifecycleEvents();
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

}
